#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define endl '\n'
const int N = 1e6 + 10;
struct node
{
	LL num, x;
};
LL a[N], b[N];
node c[N * 2];
int n, m;

bool cmp(node& a, node& b)
{
	return a.x < b.x;
}

void solve() 
{
    cin >> n >> m;
	LL A = m - n;
	LL B = 0;
	int pos = 0;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		B += a[i];
		c[++pos].x = a[i];
		c[pos].num = 0;
	}
	for(int i = 1; i <= m; i++)
	{
		cin >> b[i];
		B -= b[i];
		c[++pos].x = b[i];
		c[pos].num = 1;
	}
	sort(c + 1, c + 1 + pos, cmp);
	LL curmin = 4e18;
	LL mink = -2e9;
	for(int i = 0; i <= pos; i++)
	{
		if(c[i].num == 0) 
		{
			B -= 2 * c[i].x;
			if(i != 0) A += 2;
		}
		else 
		{
			B += 2 * c[i].x;
			if(i != 0) A -= 2;
		}
		// cout << A << " " << B << endl;
		if(A == 0)
		{
			if(abs(B) <= curmin)
			{
				curmin = abs(B);
				mink = -2e9;                                                                     
			}
			continue;
		}
		LL x1 = -((B - 1) / A), x2 = -((B + 1) / A);
		LL newf1 = abs(A * x1 + B);
		LL newf2 = abs(A * x2 + B);
		LL newf = newf1, x = x1; 	 	
		if(newf2 < newf1)
		{
			newf = newf2; x = x2;
		}
		if(newf <= curmin)
		{
			curmin = newf;
			mink = min(mink, x);
		}
		cout << A << " " << B << " " << x1 << " " << x2 << " " << newf << endl;
	}
	cout << mink << endl;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int T = 1;
	// cin >> T;
	while(T--)
	{
        solve();
	}
	return 0;
}